<%-- 
    Document   : risultato
    Created on : 24-mag-2011, 21.13.44
    Author     : dav
--%>

<%@page import="java.sql.Array"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <link href="style.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <% 
            if(request.getAttribute("result")!=null){
                
                    if(session.getAttribute("username")==null){
                    %>
                    <center><h2>Risultato della ricerca : </h2></center>
                    <table id="res_table">
                    <th>Titolo</th>
                    <th>Autore</th>
                    <th>Editore</th>
                    <th>Anno</th>
                    <%
                    ArrayList a = new ArrayList();
                    a = (ArrayList) request.getAttribute("result");
                    for(int i=0;i<a.size();i++){
                    %>
                    <tr class="<% if(i%2!=0){ out.print("chiaro"); }else{ out.print("scuro");}%>">
                            <%
                            String[] dati = new String[3]; 
                            String pd = a.get(i).toString().substring(1, a.get(i).toString().length()-1);
                            dati=pd.split(",");%>
                            <td>
                            <%
                            out.print(dati[0]);
                            %>
                            </td>
                            <td>
                            <%
                            out.print(dati[1]);
                            %>
                            </td>
                            <td>
                            <%
                            out.print(dati[2]);
                            %>
                            </td>
                            <td>
                            <%
                            out.print(dati[3]);
                            %>
                            </td>
                    </tr>
                    <%
                    } 
                    %>    
                    </table>
                    <%
                    }else{
                    %>
                    <center><h2>Risultato della ricerca : </h2></center>
                    <table id="res_table">
                    <th>Titolo</th>
                    <th>Autore</th>
                    <th>Editore</th>
                    <th>Anno</th>
                    <th>Prenota</th>
                    <%
                    ArrayList a = new ArrayList();
                    a = (ArrayList) request.getAttribute("result");
                    for(int i=0;i<a.size();i++){
                    %>
                    <tr class="<% if(i%2!=0){ out.print("chiaro"); }else{ out.print("scuro");}%>">
                            <%
                            String[] dati = new String[3]; 
                            String pd = a.get(i).toString().substring(1, a.get(i).toString().length()-1);
                            dati=pd.split(",");%>
                            <td>
                            <%
                            out.print(dati[0]);
                            %>
                            </td>
                            <td>
                            <%
                            out.print(dati[1]);
                            %>
                            </td>
                            <td>
                            <%
                            out.print(dati[2]);
                            %>
                            </td>
                            <td>
                            <%
                            out.print(dati[3]);
                            %>
                            </td>
                            <td>
                                <form action="prenota.jsp" method="POST" id="prenota">
                                <input type="hidden" name="titololibro" value="<% out.print(dati[0]); %>"/>
                                <input type="hidden" name="autorelibro" value="<% out.print(dati[1].substring(1,dati[1].length())); %>"/>
                                <input type="hidden" name="editorelibro" value="<% out.print(dati[2].substring(1,dati[2].length())); %>"/>
                                <input type="hidden" name="annolibro" value="<% out.print(dati[3].substring(1,dati[3].length())); %>"/>
                                
                                </form>
                                <a href="javascript:document.getElementById('prenota').submit()">Prenota</a>
                            </td>
                    </tr>
                    <%
                    } 
                    %>    
                    </table>
                    <%
                    }
        }
        %>
    </body>
</html>
